import Taro from '@tarojs/taro'

let mode = process.env.NODE_ENV

const setStorageSync = (key, value) => {
  try {
    Taro.setStorageSync(`${mode}_${key}`, value)
  } catch (err) {
    console.error('保存storage出错: ', JSON.parse(err))
  }
}

const getStorageSync = (key) => {
  try {
    return Taro.getStorageSync(`${mode}_${key}`)
  } catch (err) {
    console.error('获取storage出错: ', JSON.parse(err))
  }
}

const removeStorageSync = (key) => {
  try {
    Taro.removeStorageSync(`${mode}_${key}`)
  } catch (err) {
    console.error('移除storage出错: ', JSON.parse(err))
  }
}

export {
  setStorageSync,
  getStorageSync,
  removeStorageSync,
}
